@extends('common.admin_layout')
@section('title','编辑视频')
@section('content')
    <div class="app_content_div" id="app_content_div_301Index">
        <h3>编辑视频</h3>
    </div>
    <form class="form-horizontal" action="/live/{{$oLive->id}}">
        @method('PUT')
        <div class="form-group">
            <label for="name" class="col-sm-2 control-label"><span style="color:red;">*</span>直播主题</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="name" name="name" value="{{$oLive->name}}">
            </div>
        </div>

        <div class="form-group">
            <label for="sex" class="col-sm-2 control-label"><span style="color:red;">*</span>专家</label>
            <div class="col-sm-10">
                @if(\Illuminate\Support\Facades\Auth::user()->role=='admin')
                    <select id="expert_id">
                        @foreach($oExperts as $v)
                            <option value="{{$v->id}}">id：{{$v->id}}，姓名：{{$v->name}}，医院：{{$v->hospital}}</option><!-- 后面做成专家登录这里只能是自己-->
                        @endforeach
                    </select>
                @else
                    <?php
                    $expert = \App\Models\Expert::where('email',\Illuminate\Support\Facades\Auth::user()->email)->get();
                    ?>
                    <input class="form-control" type="text" readonly id="" value="{{$expert[0]->name}}"><input type="hidden" id="expert_id" value="{{$expert[0]->id}}">
                @endif
            </div>
        </div>

        <div class="form-group">
            <label for="upload_file" class="col-sm-2 control-label"><span style="color:red;">*</span>封面</label>
            <div class="col-sm-10">
                <img src="{{$oLive->image}}" style="width: 100px">
                <input type="file" id="image" name="image">
            </div>
        </div>

        <div class="form-group">
            <label for="department" class="col-sm-2 control-label"><span style="color:red;">*</span>开始时间</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="start_at" name="start_at" value="{{$oLive->start_at}}">
            </div>
        </div>
        <div class="form-group">
            <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>结束时间</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="end_at" name="end_at" value="{{$oLive->end_at}}">
            </div>
        </div>

        <div class="form-group">
            <label for="info" class="col-sm-2 control-label"><span style="color:red;">*</span>直播说明</label>
            <div class="col-sm-10">
                <script id="info" name="info" type="text/plain" style="width: 100%" >{{$oLive->info}}</script>
                <div class="hide" id="replyContent"></div>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" onclick="update()" class="btn btn-default">确定</button>
            </div>
        </div>
    </form>
    <script>
        function update()
        {
            var name=$('#name').val();
            var expert_id=$('#expert_id').val();
            var start_at=$('#start_at').val();
            var end_at=$('#end_at').val();
            var info=ue.getContent();

            $.ajaxFileUpload({
                url:'/live/{{$oLive->id}}',
                type:'PUT',
                fileElementId:'image',
                dataType:'json',

                data:{
                    'name':name,
                    'expert_id':expert_id,
                    'start_at':start_at,
                    'end_at':end_at,
                    'info':info,
                    '_token':'{{csrf_token()}}'},
                success:function (data){
                    if(data.success)
                    {
                        alert(data.msg);
                       location.href='/live';
                    }else {
                        alert(data.msg);
                    }
                }

            });
        }
        $('#start_at').datetimepicker({
            format:'Y-m-d H:i:s',
        });
        $('#end_at').datetimepicker({
            format:'Y-m-d H:i:s',
        });
        $.datetimepicker.setLocale('zh');
        var ue=UE. getEditor( 'info', {
            elementPathEnabled:false,
            saveInterval : 5000
        });
        ue. ready(function (){
            $("#replyContent").html(ue.getContent());
        });
    </script>
@endsection
